#ifndef TicToc_H
#define TicToc_H

#include <chrono>
#include <cstdlib>
#include <ctime>

namespace sys_utils
{

namespace tic
{

class TicToc
{
    public:
    TicToc( ) { tic( ); }

    void tic( ) { start = std::chrono::system_clock::now( ); }

    double toc( )
    {
        end = std::chrono::system_clock::now( );

        std::chrono::duration< double > elapsed_seconds = end - start;
        return elapsed_seconds.count( ) * 1000;
    }

    private:
    std::chrono::time_point< std::chrono::system_clock > start, end;
};

class TicTocPart
{
    public:
    TicTocPart( ) { tic( ); }

    void tic( )
    {
        start = std::chrono::system_clock::now( );
        tmp   = start;
    }

    double toc( )
    {
        std::chrono::time_point< std::chrono::system_clock > now = std::chrono::system_clock::now( );
        std::chrono::duration< double > elapsed_seconds          = now - tmp;
        tmp                                                      = now;

        return elapsed_seconds.count( ) * 1000;
    }

    double tocEnd( )
    {
        end = std::chrono::system_clock::now( );

        std::chrono::duration< double > elapsed_seconds = end - start;
        return elapsed_seconds.count( ) * 1000;
    }

    private:
    std::chrono::time_point< std::chrono::system_clock > start, end, tmp;
};
}
}
#endif // TicToc_H
